using Vin.Extension.Redis.Cache;
using Vin.Tool.Core.AssertCategory;

namespace Vin.Extension.Framework.Tools;

public class VinJwtRepeatTool
{
    internal static string VinJwtRepeatPrefix = "Repeat:";

    internal static string RepeatPrefixKey(string key, string uuid) => VinJwtRepeatPrefix +
                                                                       (key.IsNullOrEmpty() ? "" : key + ":") +
                                                                       uuid;

    public static async Task<bool> ExistsAsync(string key, string? uuid)
    {
        if (string.IsNullOrEmpty(uuid)) return false;
        return await RedisCacheManager.GetRedisCache().ExistsAsync(RepeatPrefixKey(key, uuid));
    }

    public static async Task<bool> SetAsync(string key, string? uuid, TimeSpan expireTime)
    {
        if (string.IsNullOrEmpty(uuid)) return false;
        return await RedisCacheManager.GetRedisCache().SetCacheAsync(RepeatPrefixKey(key, uuid), "1", expireTime);
    }
}